/* This do-file generates the tables in the paper "The Rise of Star Firms: Intangible Capital and Competition" by Ayyagari, Maksimovic, and Demirguc-Kunt*/
/*See regfile_constrn.do for generating the data file regressionfile.dta used in this do-file and for the construction of the different variables*/

use regressionfile, clear 
keep if year>=1990
drop if at==. | sale==. 
drop if flag==1 
* Drop negative lagged invested capital (lagged values used in ROIC definition)
g icflag2=1 if lag_investedcap_wogw3>=0 & lag_investedcap_wogw3!=.
keep if icflag2==1 

* Remove outliers
local xvar "kint_inttan costshare_cogs costshare_xopr costshare_opexPT SALES_IC capx_IC xrd_IC xsga_IC sga_IC"
foreach v of local xvar{
qui summ `v', d
g `v'_1d=`v' if `v'>=r(p1) & `v'<=r(p99)
}
g hi_intensity=1 if kint_inttan_1d>=0.75 & kint_inttan_1d!=.
replace hi_intensity=0 if kint_inttan_1d<0.75 & kint_inttan_1d!=.

* Star firm definitions 
local xvar "q_tot LP ROIC_wogw3 ROIC_wogw2 ROIC_wogw3_rdsga1 ROIC_wogw3_rdsga2 ROIC_wogw3_rdsga3 ROIC_wogw3_rdsga4"
foreach v of local xvar{
qui summ `v', d
g `v'_1d=`v' if `v'>=r(p1) & `v'<=r(p99)
bys year: egen p90`v'=pctile(`v'_1d) if `v'_1d!=., p(90)
g ab90_`v'=1 if `v'_1d>=p90`v' & `v'_1d!=.
replace ab90_`v'=0 if ab90_`v'==. & `v'_1d!=.
}
save regsub, replace
************************************************************
*Table 1 - Industry distribution of star firms
* Within Industries
tabstat ab90_ROIC_wogw3, by(indgrp) stat(mean)
tabstat ab90_ROIC_wogw2, by(indgrp) stat(mean)
* Across Industries
tab indgrp if ab90_ROIC_wogw3==1
tab indgrp if ab90_ROIC_wogw2==1


************************************************************
* Table 2 - Who are America’s stars? Correcting for intangible capital
* 2A: Markups and Star Status
xtset code year
local yvar "ROIC_wogw3_1d ab90_ROIC_wogw3 q_tot_1d ab90_q_tot"
foreach v1 of local yvar{
qui: eststo: xi: reghdfe `v1' L.LIC L.Lage L.costshare_opexPT_1d, cluster(code) absorb(naics3_real#year)
}
esttab * using t2a, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear

* 2B: Initial Markups and Star Status
xtset code year
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage mkup_ini, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage mkup_ini5, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L5.costshare_opexPT_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L10.costshare_opexPT_1d, cluster(code) absorb(naics3_real#year)
esttab * using t2b, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear

************************************************************
* Table 3 - Intangible capital, markups, and star status
* 3A: Intensity and Star Status - Role of product lifecycle
xtset code year
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d, cluster(code) absorb(year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d if hi_intensity==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d if hi_intensity==0, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d c.L.kint_inttan_1d##c.L.life1, cluster(code) absorb(naics3_real#year)
esttab * using t3a, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear

* 3B: Variance decomposition
xtset code year
g sampl=1 if ab90_ROIC_wogw3!=. & L.LIC!=. & L.Lage!=. & L.costshare_opexPT_1d!=. & L.kint_inttan_1d!=.
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage if sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d if sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d if sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage if hi_intensity==1 & sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d if hi_intensity==1 & sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d if hi_intensity==1 & sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage if hi_intensity==0 & sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d if hi_intensity==0 & sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d if hi_intensity==0 & sampl==1, cluster(code) absorb(naics3_real#year)
esttab * using t3b, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear

* Appendix Table A5: Robustness of 3A - use ROIC instead of ROIC Star
xtset code year
qui: eststo: xi: reghdfe ROIC_wogw3_1d L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d, cluster(code) absorb(year)
qui: eststo: xi: reghdfe ROIC_wogw3_1d L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ROIC_wogw3_1d L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d if hi_intensity==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ROIC_wogw3_1d L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d if hi_intensity==0, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ROIC_wogw3_1d L.LIC L.Lage L.costshare_opexPT_1d c.L.kint_inttan_1d##c.L.life1, cluster(code) absorb(naics3_real#year)
esttab * using A5, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear

* Appendix Table A6: Robustness of 3B - enter intangible intensity first and then markups
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage if sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.kint_inttan_1d if sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d if sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage if hi_intensity==1 & sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.kint_inttan_1d if hi_intensity==1 & sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d if hi_intensity==1 & sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage if hi_intensity==0 & sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.kint_inttan_1d if hi_intensity==0 & sampl==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d if hi_intensity==0 & sampl==1, cluster(code) absorb(naics3_real#year)
esttab * using tA6, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear


************************************************************
*Table 4 - Star firms, innovation output, and productivity
* Merge in patent data from Kogan et al (2017)
xtset code year
local xvar "tsm_at_1d prod_opex_1d"
foreach v2 of local xvar{
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.`v2', cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.`v2' if hi_intensity==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d L.`v2' if hi_intensity==0, cluster(code) absorb(naics3_real#year)
}
esttab * using t4, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear

************************************************************
*** Table 5 - Do star firms cut investment and output?
eststo clear
xtset code year
local yvar "capx_IC_1d xrd_IC_1d sga_IC_1d SALES_IC_1d"
foreach v1 of local yvar{
qui: xi: eststo: reghdfe `v1' L.LIC L.Lage L.ab90_ROIC_wogw3, cluster(code) absorb(year#naics3_real)
qui: xi: eststo: reghdfe `v1' L.LIC L.Lage L5.ab90_ROIC_wogw3, cluster(code) absorb(year#naics3_real)
}
esttab * using t5, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear

****************************************************************
*** Table 6 - Who are America's stars? Role of import competition 
* Merge in Chinese import shock at 4-digit NAICS
xtset code year
g impUSA_L2star=L.impUSA*L2.ab90_ROIC_wogw3
g impOTH_L2star=L.impOTH*L2.ab90_ROIC_wogw3
* 6A: Without interaction terms
xtset code year
eststo clear
local xvar "costshare_opexPT_1d ROIC_wogw3_1d SALES_IC_1d capx_IC_1d xrd_IC_1d sga_IC_1d"
foreach v1 of local xvar{
qui: xi: eststo: ivreghdfe `v1' L.LIC L.Lage (L.impUSA=L.impOTH), first cluster(naics2007_4dig) absorb(year naics2007_4dig)
}
esttab * using t6a, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust F) ar2 nogaps csv replace
eststo clear

* 6B: With interaction terms
local xvar "costshare_opexPT_1d ROIC_wogw3_1d SALES_IC_1d capx_IC_1d xrd_IC_1d sga_IC_1d"
foreach v1 of local xvar{
xi: eststo: ivreghdfe `v1' L.LIC L.Lage L2.ab90_ROIC_wogw3 (L.impUSA impUSA_L2star=L.impOTH impOTH_L2star), cluster(naics2007_4dig) first absorb(year naics2007_4dig)
}
esttab * using t6b, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear

****************************************************************
*** Table 7 - Are star firms persistent performers?
* Sales and Employment Growth
use regsub, clear
keep if year==1990 | year==1995
sort code year
bys code: g tot=_N
keep if tot==2
bys code: g id=_n
bys code: g Lsalesgr5yr=(Lsales-Lsales[_n-1])/5
g Lemp=ln(emp)
bys code: g Lemp5yr=(Lemp-Lemp[_n-1])/5
bys code: g superstar_5yrago=ab90_ROIC_wogw3[_n-1]
bys code: g LIC_5yrago=LIC[_n-1]
bys code: g Lage_5yrago=Lage[_n-1]
bys code: g ROIC_5yrago=ROIC_wogw3_1d[_n-1]
keep if id==2
save t1, replace

use regsub, clear
keep if year==1995 | year==2000
sort code year
bys code: g tot=_N
keep if tot==2
bys code: g id=_n
bys code: g Lsalesgr5yr=(Lsales-Lsales[_n-1])/5
g Lemp=ln(emp)
bys code: g Lemp5yr=(Lemp-Lemp[_n-1])/5
bys code: g superstar_5yrago=ab90_ROIC_wogw3[_n-1]
bys code: g LIC_5yrago=LIC[_n-1]
bys code: g Lage_5yrago=Lage[_n-1]
bys code: g ROIC_5yrago=ROIC_wogw3_1d[_n-1]
keep if id==2
append using t1
save t1, replace

use regsub, clear
keep if year==2000 | year==2005
sort code year
bys code: g tot=_N
keep if tot==2
bys code: g id=_n
bys code: g Lsalesgr5yr=(Lsales-Lsales[_n-1])/5
g Lemp=ln(emp)
bys code: g Lemp5yr=(Lemp-Lemp[_n-1])/5
bys code: g superstar_5yrago=ab90_ROIC_wogw3[_n-1]
bys code: g LIC_5yrago=LIC[_n-1]
bys code: g Lage_5yrago=Lage[_n-1]
bys code: g ROIC_5yrago=ROIC_wogw3_1d[_n-1]
keep if id==2
append using t1
save t1, replace

use regsub, clear
keep if year==2005 | year==2010
sort code year
bys code: g tot=_N
keep if tot==2
bys code: g id=_n
bys code: g Lsalesgr5yr=(Lsales-Lsales[_n-1])/5
g Lemp=ln(emp)
bys code: g Lemp5yr=(Lemp-Lemp[_n-1])/5
bys code: g superstar_5yrago=ab90_ROIC_wogw3[_n-1]
bys code: g LIC_5yrago=LIC[_n-1]
bys code: g Lage_5yrago=Lage[_n-1]
bys code: g ROIC_5yrago=ROIC_wogw3_1d[_n-1]
keep if id==2
append using t1
save t1, replace

use regsub, clear
keep if year==2010 | year==2015
sort code year
bys code: g tot=_N
keep if tot==2
bys code: g id=_n
bys code: g Lsalesgr5yr=(Lsales-Lsales[_n-1])/5
g Lemp=ln(emp)
bys code: g Lemp5yr=(Lemp-Lemp[_n-1])/5
bys code: g superstar_5yrago=ab90_ROIC_wogw3[_n-1]
bys code: g LIC_5yrago=LIC[_n-1]
bys code: g Lage_5yrago=Lage[_n-1]
bys code: g ROIC_5yrago=ROIC_wogw3_1d[_n-1]
keep if id==2
append using t1
save t1, replace

eststo clear
local yvar "Lsalesgr5yr Lemp5yr"
foreach v1 of local yvar{
qui: xi: eststo: reghdfe `v1' superstar_5yrago LIC_5yrago Lage_5yrago, cluster(code) absorb(year#naics3_real)
qui: xi: eststo: reghdfe `v1' ROIC_5yrago LIC_5yrago Lage_5yrago, cluster(code) absorb(year#naics3_real)
}
esttab * using t7a, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace

* ROIC and Labor Productivity
use regsub, clear
keep if year>=1990 & year<=1995
sort code year
bys code: egen LP_5yrmean=mean(LP_1d)
bys code: egen ROIC_5yrmean=mean(ROIC_wogw3_1d)
bys code: g superstar_5yrago=ab90_ROIC_wogw3 if year==1990
bys code: g LIC_5yrago=LIC if year==1990
bys code: g Lage_5yrago=Lage if year==1990
bys code: g ROIC_5yrago=ROIC_wogw3_1d if year==1990
keep if year==1990
save t2, replace

use regsub, clear
keep if year>=1995 & year<=2000
sort code year
bys code: egen LP_5yrmean=mean(LP_1d)
bys code: egen ROIC_5yrmean=mean(ROIC_wogw3_1d)
bys code: g superstar_5yrago=ab90_ROIC_wogw3 if year==1995
bys code: g LIC_5yrago=LIC if year==1995
bys code: g Lage_5yrago=Lage if year==1995
bys code: g ROIC_5yrago=ROIC_wogw3_1d if year==1995
keep if year==1995
append using t2
save t2, replace

use regsub, clear
keep if year>=2000 & year<=2005
sort code year
bys code: egen LP_5yrmean=mean(LP_1d)
bys code: egen ROIC_5yrmean=mean(ROIC_wogw3_1d)
bys code: g superstar_5yrago=ab90_ROIC_wogw3 if year==2000
bys code: g LIC_5yrago=LIC if year==2000
bys code: g Lage_5yrago=Lage if year==2000
bys code: g ROIC_5yrago=ROIC_wogw3_1d if year==2000
keep if year==2000
append using t2
save t2, replace

use regsub, clear
keep if year>=2005 & year<=2010
sort code year
bys code: egen LP_5yrmean=mean(LP_1d)
bys code: egen ROIC_5yrmean=mean(ROIC_wogw3_1d)
bys code: g superstar_5yrago=ab90_ROIC_wogw3 if year==2005
bys code: g LIC_5yrago=LIC if year==2005
bys code: g Lage_5yrago=Lage if year==2005
bys code: g ROIC_5yrago=ROIC_wogw3_1d if year==2005
keep if year==2005
append using t2
save t2, replace

use regsub, clear
keep if year>=2010 & year<=2015
sort code year
bys code: egen LP_5yrmean=mean(LP_1d)
bys code: egen ROIC_5yrmean=mean(ROIC_wogw3_1d)
bys code: g superstar_5yrago=ab90_ROIC_wogw3 if year==2010
bys code: g LIC_5yrago=LIC if year==2010
bys code: g Lage_5yrago=Lage if year==2010
bys code: g ROIC_5yrago=ROIC_wogw3_1d if year==2010
keep if year==2010
append using t2
save t2, replace

local yvar "LP_5yrmean ROIC_5yrmean"
foreach v1 of local yvar{
qui: xi: eststo: reghdfe `v1' superstar_5yrago LIC_5yrago Lage_5yrago, cluster(code) absorb(year#naics3_real)
qui: xi: eststo: reghdfe `v1' ROIC_5yrago LIC_5yrago Lage_5yrago, cluster(code) absorb(year#naics3_real)
}
esttab * using t7a, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear
****************************************************************
*** Table 8 - Intangible capital, markups, and star status: Measurement of excess cash
* ROIC5 - Alternate ROIC Definition using firm's total cash holdings
use regressionfile, clear
keep if year>=1990
drop if at==. | sale==. 
drop if flag==1 
g icflag3=1 if lag_investedcap_wogw5>=0 & lag_investedcap_wogw5!=.
keep if icflag3==1 
local xvar "ROIC_wogw5"
foreach v of local xvar{
qui summ `v', d
g `v'_1d=`v' if `v'>=r(p1) & `v'<=r(p99)
bys year: egen p90`v'=pctile(`v'_1d) if `v'_1d!=., p(90)
g ab90_`v'=1 if `v'_1d>=p90`v' & `v'_1d!=.
replace ab90_`v'=0 if ab90_`v'==. & `v'_1d!=.
}
local xvar "costshare_opexPT kint_inttan"
foreach v of local xvar{
qui summ `v', d
g `v'_1d=`v' if `v'>=r(p1) & `v'<=r(p99)
}

xtset code year
local yvar "ab90_ROIC_wogw5"
foreach v of local yvar{
qui: eststo: xi: reghdfe `v' L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe `v' L.LIC L.Lage L.costshare_opexPT_1d L.c.kint_inttan_1d##c.L.life1, cluster(code) absorb(naics3_real#year)
}
esttab * using t8a, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace

* ROIC7 - Alternate ROIC Definition where we define excess cash to be any cash over 1% of sales
use regressionfile, clear
keep if year>=1990
drop if at==. | sale==. 
drop if flag==1 
g icflag7=1 if lag_investedcap_wogw7>=0 & lag_investedcap_wogw7!=.
keep if icflag7==1 
local xvar "ROIC_wogw7"
foreach v of local xvar{
qui summ `v', d
g `v'_1d=`v' if `v'>=r(p1) & `v'<=r(p99)
bys year: egen p90`v'=pctile(`v'_1d) if `v'_1d!=., p(90)
g ab90_`v'=1 if `v'_1d>=p90`v' & `v'_1d!=.
replace ab90_`v'=0 if ab90_`v'==. & `v'_1d!=.
}
local xvar "costshare_opexPT kint_inttan"
foreach v of local xvar{
qui summ `v', d
g `v'_1d=`v' if `v'>=r(p1) & `v'<=r(p99)
}
xtset code year
local yvar "ab90_ROIC_wogw7"
foreach v of local yvar{
qui: eststo: xi: reghdfe `v' L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe `v' L.LIC L.Lage L.costshare_opexPT_1d L.c.kint_inttan_1d##c.L.life1, cluster(code) absorb(naics3_real#year)
}
esttab * using t8a, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace


* ROIC8 - Alternate ROIC Definition where we define excess cash to be any cash over 10% of sales
use regressionfile, clear
keep if year>=1990
drop if at==. | sale==. 
drop if flag==1 
g icflag8=1 if lag_investedcap_wogw8>=0 & lag_investedcap_wogw8!=.
keep if icflag8==1 
local xvar "ROIC_wogw8"
foreach v of local xvar{
qui summ `v', d
g `v'_1d=`v' if `v'>=r(p1) & `v'<=r(p99)
bys year: egen p90`v'=pctile(`v'_1d) if `v'_1d!=., p(90)
g ab90_`v'=1 if `v'_1d>=p90`v' & `v'_1d!=.
replace ab90_`v'=0 if ab90_`v'==. & `v'_1d!=.
}
local xvar "costshare_opexPT kint_inttan"
foreach v of local xvar{
qui summ `v', d
g `v'_1d=`v' if `v'>=r(p1) & `v'<=r(p99)
}
xtset code year
local yvar "ab90_ROIC_wogw8"
foreach v of local yvar{
qui: eststo: xi: reghdfe `v' L.LIC L.Lage L.costshare_opexPT_1d L.kint_inttan_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe `v' L.LIC L.Lage L.costshare_opexPT_1d L.c.kint_inttan_1d##c.L.life1, cluster(code) absorb(naics3_real#year)
}
esttab * using t8a, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace


****************************************************************
* Appendix Table A1 - Summary Statistics
use regsub, clear
xtset code year
qui: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.costshare_opexPT_1d, cluster(code) absorb(naics3_real#year)
summ ab90_ROIC_wogw3 ROIC_wogw3_1d LIC Lage costshare_opexPT_1d kint_inttan_1d  costshare_opexPT_1d if e(sample)==1


****************************************************************
* Appendix Table A2 - Markups and star status: Varying proportions of SGA in ROIC
use regsub, clear
xtset code year
sort code year
local yvar "ab90_ROIC_wogw3_rdsga1 ab90_ROIC_wogw3_rdsga2 ab90_ROIC_wogw3 ab90_ROIC_wogw3_rdsga3 ab90_ROIC_wogw3_rdsga4"
foreach v1 of local yvar{
qui: eststo: xi: reghdfe `v1' L.LIC L.Lage L.costshare_opexPT_1d, cluster(code) absorb(naics3_real#year)
}
esttab * using A2, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear

****************************************************************
* Appendix Table A3 - Markups and star status: Alternative definitions of markups
use regsub, clear
xtset code year
local xvar "ab90_ROIC_wogw3"
foreach v1 of local xvar{
qui: eststo: xi: reghdfe `v1' L.LIC L.Lage L.costshare_cogs_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe `v1' L.LIC L.Lage L.costshare_xopr_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe `v1' L.LIC L.Lage L.costshare_opexPT_1d, cluster(code) absorb(naics3_real#year)
}
esttab * using A3, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear


****************************************************************
* Appendix Table A4 - Markups and star status: Additional robustness
use regsub, clear
xtset code year
local yvar "ROIC_wogw3_1d ab90_ROIC_wogw3 q_tot_1d ab90_q_tot"
foreach v1 of local yvar{
qui: eststo: xi: reghdfe `v1' L.LIC L.Lage L.costshare_opexPT_1d, cluster(code) absorb(code year)
}
esttab * using A4, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear

****************************************************************
* Appendix Table A7 - Traina markups (OPEX) versus our markups (OPEX*)
use regsub, clear
xtset code year
g sampl2=1 if L.costshare_xopr_1d!=. & L.costshare_opexPT_1d!=. & L.costshare_cogs_1d!=.
local xvar "costshare_xopr_1d costshare_opexPT_1d"
foreach v1 of local xvar{
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.`v1' if sampl2==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.`v1' if hi_intensity==1 & sampl2==1, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC_wogw3 L.LIC L.Lage L.`v1' if hi_intensity==0 & sampl2==1, cluster(code) absorb(naics3_real#year)
}
esttab * using tA7, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear


****************************************************************
* Appendix Table A8 - Alternative definitions of intangible capital
use regsub, clear
local xvar "kint_inttan1 kint_inttan2 kint_inttan3"
foreach v of local xvar{
qui summ `v', d
g `v'_1d=`v' if `v'>=r(p1) & `v'<=r(p99)
}

local xvar "ROIC1 ROIC2 ROIC3"
foreach v of local xvar{
qui summ `v', d
g `v'_1d=`v' if `v'>=r(p1) & `v'<=r(p99)
bys year: egen p90`v'=pctile(`v'_1d) if `v'_1d!=., p(90)
g ab90_`v'=1 if `v'_1d>=p90`v' & `v'_1d!=.
replace ab90_`v'=0 if ab90_`v'==. & `v'_1d!=.
}

eststo clear
xtset code year
qui: eststo: xi: reghdfe ab90_ROIC1 L.LIC1 L.Lage L.costshare_opexPT_1d L.kint_inttan1_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC2 L.LIC2 L.Lage L.costshare_opexPT_1d L.kint_inttan2_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC3 L.LIC3 L.Lage L.costshare_opexPT_1d L.kint_inttan3_1d, cluster(code) absorb(naics3_real#year)

qui: eststo: xi: reghdfe ab90_ROIC1 L.LIC1 L.Lage mkup_ini5 L.kint_inttan1_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC2 L.LIC2 L.Lage mkup_ini5 L.kint_inttan2_1d, cluster(code) absorb(naics3_real#year)
qui: eststo: xi: reghdfe ab90_ROIC3 L.LIC3 L.Lage mkup_ini5 L.kint_inttan3_1d, cluster(code) absorb(naics3_real#year)
esttab * using A8, b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) scalars (N N_clust) ar2 nogaps csv replace
eststo clear
